import {
    Component, ComponentFactoryResolver, ElementRef, ViewContainerRef, Renderer2, OnInit, OnDestroy
} from '@angular/core';
import { EsCommonService } from '../../../common/escommon.service';
import { Router, NavigationStart, NavigationEnd, NavigationCancel, NavigationError, RoutesRecognized } from '@angular/router';
import { Subscription } from 'rxjs/Subscription';

@Component({
    templateUrl: './watching.component.html',
    styleUrls: ['./watching.component.css', '../../../app.component.css'],
})
export class WatchingComponent implements OnInit, OnDestroy {
    routerListener: Subscription;
    ngOnDestroy(): void {
        if (this.routerListener) {
            this.routerListener.unsubscribe();
        }
    }
    show: string;

    constructor(private esCommonService: EsCommonService, private router: Router) {
        this.show = "psy";
        this.routerListener = router.events.subscribe(event => {
            router.events.subscribe(event => {
                if (event instanceof NavigationStart) {
                    //不处理
                } else if (event instanceof NavigationEnd) {
                    let url = event.url;
                    let urls = url.split('/');
                    if (urls[urls.length - 1] == 'cloudmachine') {
                        this.show = "cloud";
                    } else {
                        this.show = "psy";
                    }
                } else if (event instanceof NavigationCancel) {
                    //不处理
                } else if (event instanceof NavigationError) {
                    //不处理
                } else if (event instanceof RoutesRecognized) {
                    //不处理
                }
            });
        });
    }
    ngOnInit(): void {
    }
    goto(path) {
        this.show = path;
        if (path == "psy") {
            this.router.navigate(['/home/warn/watching/psmachine']);
        }
        if (path == "cloud") {
            this.router.navigate(['/home/warn/watching/cloudmachine'])
        }

    }
}